package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.SellOrderBean;
import com.project.mapper.ISellInfoMapper;
import com.project.mapper.ISellOrderMapper;
import com.project.service.ISellOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;

@Service
@Transactional
public class SellOrderServiceImpl implements ISellOrderService {
    @Autowired
    private ISellOrderMapper sellOrderMapper;
    @Autowired
    private ISellInfoMapper sellInfoMapper;
    @Override
    public IPage<SellOrderBean> findByItem(Integer pageNO, String customer, LocalDate startDate, LocalDate endDate) {
        QueryWrapper<SellOrderBean> qw = new QueryWrapper<>();
        if (customer !=null && customer.length() !=0){
            qw.like("so_customer",customer);
        }
        if (startDate !=null){
            qw.ge("so_date",startDate);
        }
        if (endDate !=null){
            qw.le("so_date",endDate);
        }
        return sellOrderMapper.selectPage(new Page<>(pageNO,3),qw);
    }

    @Override
    public SellOrderBean findById(Integer sellOrderId) {
        SellOrderBean sellOrderBean=sellOrderMapper.selectById(sellOrderId);
        sellOrderBean.setSellInfoBeanList(sellInfoMapper.findByBuyOrderId(sellOrderId));
        return sellOrderBean;
    }
}
